$(document).ready(function(){
    //店铺照片上传
    function setShopImg(res){
        // console.log(res);
        document.getElementById('ImgUrl').value = res
    }
    imgUpload('imgInput','imgShow',setShopImg);

    //获取店铺信息
    let shopContent = {};
    function getShopContent(){
        getAjax(`${global.apiUrl}/get_community_service_shop_content`,res=>{
            console.log(res);
            shopContent = res;
            $('#s_name').val(res.shop_name);
            $('#s_address').val(res.address);
            $('#s_opentime').val(res.open_time);
            $('#s_closetime').val(res.close_time);
            $('#s_gg').val(res.gg);
            $('#s_phone').val(res.shop_phone);
            $('#ImgUrl').val(res.head_img);
            let img = `<img src="${res.head_img}"/>`;
            $('#imgShow').html(img)
        },{
            id:global.community_service_shop_id
        })
    }
    getShopContent();
    function setShopContent(){
        let shop_name = $('#s_name').val();
        let address = $('#s_address').val();
        let open_time = $('#s_opentime').val();
        let close_time = $('#s_closetime').val();
        let gg = $('#s_gg').val();
        let shop_phone = $('#s_phone').val();
        let head_img = $('#ImgUrl').val();
        let pro = {
            id:global.community_service_shop_id,
            shop_name:shop_name,
            address:address,
            open_time:open_time,
            close_time:close_time,
            gg:gg,
            shop_phone:shop_phone,
            head_img:head_img
        };
        pro = JSON.stringify(pro);
        console.log(pro);
        getAjax(`${global.apiUrl}/admin_save_community_service_shop_content`,res=>{
            // console.log(res);
            if(res == 1){
                alert('店铺信息提交成功！');
            }
            if(res == 0){
                alert('店铺信息未发生变化，修改失败！')
            }
        },{
            pro:pro
        })
    }
    $('#submit_btn').on('click',function(){
        setShopContent();
    })
})
